package cn.bxg;

import java.util.concurrent.locks.ReentrantLock;

public class maipiao implements Runnable {
    private int ticket = 100;
    public Object a = new Object();
    private ReentrantLock lock = new ReentrantLock();

    @Override
    public void run() {

        while (true) {
            try {
                lock.lock();
                if (ticket <= 0) {
                    break;
                } else {
                    Thread.sleep(100);

                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }
    }
}
